package com.iap.client.service
{
	import com.iap.app.StatusCode;
	import com.iap.app.data.AppData;
	import com.iap.app.data.IAppData;
	import com.iap.app.model.ServiceResponse;
	import com.iap.client.event.UserEvent;
	import com.iap.common.translator.UserTranslator;
	
	import org.robotlegs.mvcs.Actor;

	public class UserService extends Actor implements IUserService
	{
		[Inject]
		public var data:IAppData;

		private var result:Array;
		
		public function UserService()
		{
		}
		
		public function getList():void
		{
			data.dataComplete.add(responseHandler);
			data.load(this, AppData.JOB_GET);
		}
		
		private function responseHandler(response:ServiceResponse):void
		{
			data.dataComplete.remove(responseHandler);
			if(response.status.code != StatusCode.OK)
				return;
			result = UserTranslator.translateFromArray(response.result as Array);
			dispatch(new UserEvent(UserEvent.GET_LIST_RESPONSE, result));
		}
	}
}